package com.panshi.controller.home;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.panshi.api.DetailApi;
import com.panshi.api.IMessagApi;
import com.panshi.api.UserGetApi;
import com.panshi.utils.GetSessionUser;
import com.panshi.vo.CollectVO;
import com.panshi.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("zx")
public class DetailController {
    @Autowired
    DetailApi detailApi;

    @Autowired
    UserGetApi userGetApi;

    //收藏
    @CrossOrigin(origins = "*", maxAge = 3600)
    @PostMapping("/insert/collect")
    @ResponseBody
    public Boolean insertCollect(@Validated CollectVO collectVO) {
        System.out.println(collectVO);
        return detailApi.insertCollect(collectVO);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/detail/{id}")
    public String laydt(@PathVariable(value = "id") Integer id, Map<String, Object> model) {
        int userId = GetSessionUser.getSessionUserId();
        model.put("userId",userId);
        model.put("loginUser",userGetApi.findUserByUid(userId + ""));
        model.put("titlelist", detailApi.listTitleVOs());
        model.put("detail", detailApi.getArticleOkVO(id));
        model.put("other", detailApi.listDetailOtherArticleOkVOs(id));
        return "home_page/detail";
    }
}
